package inutan.game.context;

import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public abstract class UserContext {

    long userId;

    public UserContext(long userId) {
        this.userId = userId;
    }


    /**
     * 玩家登陆初始化 玩家数据
     */
    public void init(Runnable runnable) {
        Executor loader = Executors.newVirtualThreadPerTaskExecutor();
        CompletableFuture<Optional<RoleInfo>> roleFuture = CompletableFuture.supplyAsync(this::roleInfo, loader);
        CompletableFuture<List<MailInfo>> mailFuture = CompletableFuture.supplyAsync(this::mailInfo, loader);
        CompletableFuture<List<GachaInfo>> gachaFuture = CompletableFuture.supplyAsync(this::gachaInfo, loader);
        CompletableFuture<List<CardInfo>> cardFuture = CompletableFuture.supplyAsync(this::cardInfo, loader);
        CompletableFuture<Void> allFutures = CompletableFuture.allOf(roleFuture,mailFuture, gachaFuture, cardFuture);
        allFutures.thenRun(runnable);
    }

    abstract Optional<RoleInfo> roleInfo();

    abstract List<MailInfo> mailInfo();

    abstract List<GachaInfo> gachaInfo();
    abstract List<CardInfo> cardInfo();
}

